package cn.yunhe.crm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.yunhe.crm.dao.ContactMapper;
import cn.yunhe.crm.entity.Contact;
import cn.yunhe.crm.entity.ContactExample;
import cn.yunhe.crm.entity.EmpExample;
import cn.yunhe.crm.entity.OrganizationExample;
@Service("ContactBiz")
public class ContactService {

	@Autowired
	private ContactMapper contactMapper;
	
	public void setContactMapper(ContactMapper contactMapper) {
		this.contactMapper = contactMapper;
	}

	/**
	 * ��ѯ������ϵ��
	 * @return
	 */
	public List<Contact> findAllContact(){
		return contactMapper.findAllContact();
	}
	
	/**
	 * ����δɾ��״̬����ѯ������ϵ��
	 * @return
	 */
	public List<Contact> selectByExample(){
		ContactExample contactExample = new ContactExample();
		ContactExample.Criteria criteria= contactExample.createCriteria();
		criteria.andDelstateEqualTo(0);
		List<Contact> list=contactMapper.selectByExample(contactExample);
		return list;
	}
	
	
	
	/**
	 * �鿴��ϵ��ϵ������
	 * @param id
	 * @return
	 */
	 public Contact findContactdetail(Integer id){
		
		return contactMapper.findContactdetail(id);
	}
	/**
	 * ����id�ı���ϵ��״̬��ʵ��ɾ��
	 * @param id
	 * @return
	 */
	public int editContactStateById(Integer id){
		int flag=contactMapper.editContactStateById(id);
		if(flag>0){
			return 1;
		}
			return 0;
	}
	
	/**
	 * �����ϵ��
	 * @param record
	 * @return
	 */
	public int insertContact(Contact record){
		int flag=contactMapper.insert(record);
		if(flag>0){
			return 1;
		}else {
			return 0;
		}
	}
	
	/**
	 * ����id��ѯ��ϵ��
	 * @param id
	 * @return
	 */
	public Contact selectByPrimaryKey(Integer id){
		Contact contact= contactMapper.selectByPrimaryKey(id);
		return contact;
	}
	
	public int updateContactById(Contact contact){
		int flag=contactMapper.updateContactById(contact);
		if(flag>0){
			return 1;
		}else{
			return 0;
		}
	}
	
	
	public  Contact findContactByPhone(String phone){
		Contact contact=contactMapper.findContactByPhone(phone);
		return contact;
	}
	
	
	
	
	
}
